package packagecmdimp;

import package1.OrderConsole;
import package2.OrderApplication;
import package2.OrderDao;
import packageCommand.SystemCommand;
import packagerole.User;

public class UserLoginCommand extends SystemCommand {

    @Override
    public void execute() {
       OrderDao dao = new OrderDao();
        
        String username = OrderConsole.askUserInput("请输入用户名");
        // check username 
        while (!dao.isUsernameExists(username)) {
        	OrderConsole.println("用户名不存在！");
            username = OrderConsole.askUserInput("请输入用户名");
        }

        String password = OrderConsole.askUserInput("请输入密码");
        
        User user = dao.userLogin(username, password);
        
        if (user == null) {
        	OrderConsole.println("登录失败！用户名／密码不正确");
            return;
        }

        OrderConsole.println("欢迎你回来，" + user.getName());
        OrderApplication.getInstance().setPlayerProfile(user);
    }

}
